<?php

	include_once('classes/view.php');
	
	if (isset($_SESSION['user_id']) && $_SESSION['user_id'] != ''){
		ShowEditForm();
	} else {
		ShowMessage();
	}
	
	die();

	function ShowEditForm(){
		View::displayHeader();
		
		echo '
		<script type="text/javascript">
			function validateOnSubmit() {
		    	var elem;
		    	var myCountErrors=0;
		    		    	
		    	if (!validatePassword(document.forms.register.old_haslo, document.forms.register.old_haslo, \'inf_old_haslo\', \'inf_old_haslo\')) myCountErrors += 1;
		    	if (!validatePassword(document.forms.register.new_haslo1, document.forms.register.new_haslo2, \'inf_new_haslo1\', \'inf_new_haslo2\')) myCountErrors += 2;
		    	 
		    	if (myCountErrors > 1)  alert(\'Należy poprawić kilka pól.\');
		    	else if (myCountErrors == 1) alert(\'Należy poprawić jedno pole.\');
		
		    	return (myCountErrors == 0);
		  	};
		</script>
		
		<form name="register" method="POST" onsubmit="return validateOnSubmit()" action="user_update_password.php">
			<div class="box">
			<h1>Wpisz w pola obecne oraz nowe hasło</h1>
			  <label>
			    <span>Podaj stare hasło: </span>
			    <input class="wpis" type="password" name="old_haslo" id="old_haslo" size="70" maxlength="30" />
			    <i id="inf_old_haslo">Pole wymagane</i>
			  </label>
			  
			  <label>
			    <span>Podaj nowe hasło: </span>
			    <input class="wpis" type="password" name="new_haslo1" id="new_haslo1" size="70" maxlength="40" />
			    <i id="inf_new_haslo1">Pole wymagane</i>
			  </label>
			  
			  <label>
			    <span>Ponownie nowe hasło:</span>
			    <input class="wpis" type="password" name="new_haslo2" id="new_haslo2" size="70" maxlength="70" />
			    <i id="inf_new_haslo2">Pole wymagane</i>
			  </label>

			  <label>
			    <input class="button" type="Submit" name="Submit" value="Wyślij" />
			  </label>
			</div>
		</form><br /><br /><br /><br />
		';
		
		View::displayFooter();
	}

	function ShowMessage(){
		View::displayHeader();
		View::displayMiddle("Musisz być zarejestrowany i zalogowany aby tutaj wejść");
		View::displayFooter();
	}
?>